package pl.ptemich.tankwars.tools;

import java.util.HashMap;
import java.util.Map;

import org.newdawn.slick.Color;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;

import pl.ptemich.tankwars.states.RegisteredState;

public class StateTools {

  private static StateBasedGame game;
  
  private static Map<String, RegisteredState> states = new HashMap<String, RegisteredState>();
  
  
  
  
  public static void registerGame(StateBasedGame gameToRegister) {
    game = gameToRegister;
  }
  
  public static void stateTransition(Class<? extends RegisteredState> stateClazz) {
    game.enterState(StateTools.getStateInstance(stateClazz).getID(), 
                    new FadeOutTransition(Color.black), 
                    new FadeInTransition(Color.black));
  }


  public static int registerState(RegisteredState state) {
    states.put(state.getClass().getSimpleName(), state);
    return states.size();
  }
  
  public static RegisteredState getStateInstance(Class<? extends RegisteredState> stateClazz) {
    return states.get(stateClazz.getSimpleName());
  }
  
}
